/** @file    wCommunication.cpp
 *  @author  Alessandro Polo
 *  @version $Id: wCommunication.cpp 2658 2010-06-15 21:45:46Z alex $
 *  @brief
 * The header for this class can be found in wCommunication.h, check that file
 * for class description.
 ****************************************************************************/
/* Copyright (c) 2007-2010, WOSH - Wide Open Smart Home 
 * by Alessandro Polo - OpenSmartHome.com
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the OpenSmartHome.com WOSH nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY Alessandro Polo ''AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL Alessandro Polo BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ****************************************************************************/

 #include "wCommunication.h"

 #include <core/ObjectAllocator.h>
 #include <framework/gui/GuiUtilities.h>

 #include "ui_wCommunication_TextMessage.h"
 #include "ui_wCommunication_FileMessage.h"


using namespace std;
namespace wosh {
 namespace gui {

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

 WOSH_REGISTER(wosh::gui::wCommunication_TextMessage, "wosh::gui::IWidgetSerializable", 1.0, _static_wCommunication_TextMessage )
 WOSH_GUI_MAP(wosh::gui::wCommunication_TextMessage, "wosh::communication::TextMessage", 0.0, _static_Map_wCommunication_TextMessage )

wCommunication_TextMessage::wCommunication_TextMessage( QWidget* parent )
	: QWidget(parent) {
	this->m_ui = new Ui::wCommunication_TextMessage();
	this->m_ui->setupUi(this);

	setWindowIcon( GuiUtilities::createIconFor( getSerializableType() ) );
	resize(260, 140);
 }

wCommunication_TextMessage::~wCommunication_TextMessage() {
	delete this->m_ui;
 }

WRESULT wCommunication_TextMessage::loadObject( const wosh::communication::TextMessage* txt_message ) {
	if ( txt_message == NULL ) {
		setWindowTitle( tr("%1 [NULL]").arg(getSerializableType()) );
		this->m_ui->txtBody->setText("");
		return WRET_OK;
	 }
	this->m_ui->txtBody->setText( txt_message->getPlain().c_str() );

	return WRET_OK;
 }

WRESULT wCommunication_TextMessage::saveObject( wosh::communication::TextMessage* txt_message ) const {
	if ( txt_message == NULL ) return WRET_ERR_PARAM;
	txt_message->setPlain( this->m_ui->txtBody->toPlainText().toLatin1().data() );

	return WRET_OK;
 }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

 WOSH_REGISTER(wosh::gui::wCommunication_FileMessage, "wosh::gui::IWidgetSerializable", 1.0, _static_wCommunication_FileMessage )
 WOSH_GUI_MAP(wosh::gui::wCommunication_FileMessage, "wosh::communication::FileMessage", 0.0, _static_Map_wCommunication_FileMessage )

wCommunication_FileMessage::wCommunication_FileMessage( QWidget* parent )
	: QWidget(parent) {
	this->m_ui = new Ui::wCommunication_FileMessage();
	this->m_ui->setupUi(this);

	setWindowIcon( GuiUtilities::createIconFor( getSerializableType() ) );
	resize(260, 140);
 }

wCommunication_FileMessage::~wCommunication_FileMessage() {
	delete this->m_ui;
 }

WRESULT wCommunication_FileMessage::loadObject( const wosh::communication::FileMessage* file_message ) {
	if ( file_message == NULL ) {
		setWindowTitle( tr("%1 [NULL]").arg(getSerializableType()) );
		return WRET_OK;
	 }
	return WRET_OK;
 }

WRESULT wCommunication_FileMessage::saveObject( wosh::communication::FileMessage* file_message ) const {
	if ( file_message == NULL ) return WRET_ERR_PARAM;
	return WRET_OK;
 }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

 }; // namespace gui
}; // namespace wosh
